<?php 
include_once("config.php");
$valid_users = array_keys($valid_passwords);
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
	header('WWW-Authenticate: Basic realm="My Realm"');
	header('HTTP/1.0 401 Unauthorized');
	die ("Not authorized");
}
include_once("config.php");
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8mb4")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
if (isset($_POST['submit']) && isset($_POST['pa'])){
	var_dump($_POST);
	$ja=$_POST['pa'];
	$jb=$_POST['pb'];
	$jc=$_POST['pc'];
	$query=$mysqli->query("select id from hshu where type='pa'  limit 0, 1");
	if($query->num_rows>0){
		
		$mysqli->query("update hshu set  num='".$ja."',create_time='".date("Y-m-d H:i:s")."' where type='pa'  ");
	}else{
		$mysqli->query("insert into hshu(type,num,create_time) values('pa','".$ja."','".date("Y-m-d H:i:s")."') ");
	}
	$query=NULL;
	$query=$mysqli->query("select id from hshu where type='pb'  limit 0, 1");
	if($query->num_rows>0){
		$mysqli->query("update hshu set  num='".$jb."',create_time='".date("Y-m-d H:i:s")."' where type='pb'  ");
	}else{
		$mysqli->query("insert into hshu(type,num,create_time) values('pb','".$jb."','".date("Y-m-d H:i:s")."') ");
	}
	$query=NULL;
	$query=$mysqli->query("select id from hshu where type='pc'  limit 0, 1");
	if($query->num_rows>0){
		$mysqli->query("update hshu set  num='".$jc."',create_time='".date("Y-m-d H:i:s")."' where type='pc'  ");
	}else{
		$mysqli->query("insert into hshu(type,num,create_time) values('pc','".$jc."','".date("Y-m-d H:i:s")."') ");
	}
	header("Location:  c.php?act=3");
	exit;
}
$query=$mysqli->query("select type,num from hshu limit 0, 100");
$data=array();
while ($list=$query->fetch_array()){
	$data[$list['type']] =$list['num'];
}
?><!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>周生生</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link rel="shortcut icon" href="http://wechat.levi.com.cn/attachment/images/global/wechat.jpg" />
	<link href="./resource/css/bootstrap.min.css" rel="stylesheet">
	<link href="./resource/css/font-awesome.min.css" rel="stylesheet">
	<link href="./resource/css/common.css" rel="stylesheet">
	<script>var require = { urlArgs: 'v=2015080716' };</script>
	<script src="./resource/js/require.js"></script>
	<script src="./resource/js/app/config.js"></script>
	<script src="./resource/js/lib/jquery-1.11.1.min.js"></script>
	<link rel='stylesheet' href='../css/sweet-alert.css?v=12' />
	<script src="../js/sweet-alert.min.js"></script>
	
	<!--[if lt IE 9]>
		<script src="./resource/js/html5shiv.min.js"></script>
		<script src="./resource/js/respond.min.js"></script>
	<![endif]-->
	<script type="text/javascript">
	if(navigator.appName == 'Microsoft Internet Explorer'){
		if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
			alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
		}
	}

	</script>
</head>
<body>	<div class="navbar navbar-static-top" role="navigation">
	    <br />
		<div class="container-fluid"><img style="position:relative;margin:0px auto;display:block;" src="logo.png"></div>
	</div>
	<div class="container-fluid">
				<div class="row">
						<div class="col-xs-12 col-sm-3 col-lg-2 big-menu">
						<div class="panel panel-default">
						<div class="panel-heading">
							<h4 class="panel-title">基本功能</h4>
							<a class="panel-collapse" data-toggle="collapse" href="#frame-0">
								<i class="fa fa-chevron-circle-down"></i>
							</a>
						</div>
							<?php include_once 'menua.php'; ?>
					</div>
							
									</div>
				<div class="col-xs-12 col-sm-9 col-lg-10">
<div class="clearfix ng-cloak" ng-controller="replyForm">
	<form id="reply-form" class="form-horizontal form" action="c.php" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<div class="col-sm-12">
				<div class="panel panel-default">
					<ul class="list-group">
						<li class="list-group-item">
							<div class="form-group">
								<label class="col-xs-12 col-sm-3 col-md-2 control-label">一等奖中奖概率</label>
								<div class="col-sm-6 col-md-8 col-xs-12">
									<input type="text" class="control-label col-md-4" style="text-align:left;" id="a" name="pa" value="<?php echo $data['pa']; ?>"   />
									<span class="help-block">
										<strong class="text-danger">&nbsp;&nbsp; %</strong>
									</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-12 col-sm-3 col-md-2 control-label">二等奖中奖概率</label>
								<div class="col-sm-6 col-md-8 col-xs-12">
									<input type="text" class="control-label col-md-4" style="text-align:left;" id="b"  name="pb" value="<?php echo $data['pb']; ?>"   />
									<strong class="text-danger">&nbsp;&nbsp; %</strong>
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-12 col-sm-3 col-md-2 control-label">50元优惠券中奖概率</label>
								<div class="col-sm-6 col-md-8 col-xs-12">
									<input type="text" class="control-label col-md-4" style="text-align:left;" id="c"  name="pc" value="<?php echo $data['pc']; ?>"   />
									<span class="help-block"></span>
									<span class="help-block">
										<strong class="text-danger">&nbsp;&nbsp; %</strong>
									</span>
								</div>
							</div>
							
						</li>
					</ul>
				</div> 
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" id="submit" value="保存" class="btn btn-primary col-lg-1" />
				
			</div>
		</div>
	</form>
</div><span style="font-size:12px;color:red;"></span>
			</div>
		</div>
		
	</div>




	<script>
	require(['angular.sanitize', 'bootstrap', 'underscore', 'util'], function(angular, $, _, util){
		angular.module('app', ['ngSanitize']).controller('replyForm', function($scope, $http){});
		angular.bootstrap(document, ['app']);
	});
	require(['bootstrap']);
    $("#submit").click(function(){
       var _a=parseInt($("#a").val());
       var _b=parseInt($("#b").val());
       var _c=parseInt($("#c").val());
       if(_a == ''){
           swal("请设置 型格奖中奖概率");
    	   return false;
         }
       if(_b == ''){
           swal("请设置 风尚奖中奖概率");
    	   return false;
         }
       if(_c == ''){
           swal("请设置 50元优惠券中奖概率");
    	   return false;
        }
        var _total=_a+_b+_c;
        if(100 != _total){
        	 swal("概率总和不等于100%,为"+_total+"%  请设置正确的概率");
        	 
      	   return false;
        }
       
           
     });
	
	</script>
	
</body>
</html>
